package com.lt.test.consumer.web.shiro;

import org.apache.shiro.cache.Cache;
import org.apache.shiro.cache.CacheException;
import org.apache.shiro.session.Session;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * Created by zhengchuan on 2017/6/13.
 */
public class CustomSesseionCache implements Cache<Serializable, Session> {
    private static final Map<Serializable, Session> map = new HashMap<>();
    @Override
    public Session get(Serializable key) throws CacheException {
        return map.get(key);
    }

    @Override
    public Session put(Serializable key, Session session) throws CacheException {
        map.put(key, session);
        return session;
    }

    @Override
    public Session remove(Serializable key) throws CacheException {
        Session session = map.get(key);
        if (session != null) {
            map.remove(key);
            return session;
        }
        return null;
    }

    @Override
    public void clear() throws CacheException {
        map.clear();
    }

    @Override
    public int size() {
        return map.size();
    }

    @Override
    public Set<Serializable> keys() {
        return map.keySet();
    }

    @Override
    public Collection<Session> values() {
        return map.values();
    }
}
